package kr.hkit.androidcomplete03.DomParser.common;

import java.util.ArrayList;

import kr.hkit.androidcomplete03.R;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.sax.StartElementListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class MyAdapterList extends BaseAdapter {
	private ArrayList<DaeguItem> itemList;
	private LayoutInflater inflater;
	TextView itemLink;
	
	public MyAdapterList(Context context, ArrayList<DaeguItem> arList) {
		this.itemList = arList;
		this.inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return itemList.size();
	}

	@Override
	public Object getItem(int position) {
		return itemList.get(position).getAuthor();
		 //return itemList.get(position).getLink();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.datarow, parent, false);
						
		}
		
		//TextView itemAuthor = (TextView)convertView.findViewById(R.id.itemAuthor);
		//TextView itemCategory = (TextView)convertView.findViewById(R.id.itemCategory);
		TextView itemTitle = (TextView) convertView.findViewById(R.id.itemTitle);
		itemLink = (TextView) convertView.findViewById(R.id.itemLink);
		TextView itemPubDate = (TextView) convertView.findViewById(R.id.itemPubDate);
		TextView itemDescription = (TextView) convertView.findViewById(R.id.itemDescription);

		//itemAuthor.setText(itemList.get(position).getAuthor());
		//itemCategory.setText(itemList.get(position).getCategory());
		itemTitle.setText(itemList.get(position).getTitle());
		itemLink.setText(itemList.get(position).getLink());
		itemPubDate.setText(itemList.get(position).getPubDate());
		itemDescription.setText(itemList.get(position).getDescription());


		convertView.setTag(getItem(position));
		
		itemLink.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Uri uri = Uri.parse(itemLink.getText().toString());
				Intent intent = new Intent(Intent.ACTION_VIEW, uri);
				
			}
			
		});
		
		return convertView;
	}
	
	
}
